// JavaScript Document

/*function $(id) {
	return document.getElementById(id);
}*/
function mueveReloj() {
    momentoActual = new Date();
	
    hora = momentoActual.getHours();
    minuto = momentoActual.getMinutes();
    segundo = momentoActual.getSeconds();
	
	tiempo = "a.m."
	if (parseInt(hora) == 0) {
		hora = 12;
	} else if (parseInt(hora) > 12) {
		hora = hora - 12;
		tiempo = "p.m."
	}
	
	if (parseInt(minuto) >= 0 && parseInt(minuto) <= 9)
		minuto = "0" + minuto;
		
	if (parseInt(segundo) >= 0 && parseInt(segundo) <= 9)
		segundo = "0" + segundo;

    horaImprimible = hora + ":" + minuto + ":" + segundo + " " + tiempo;

    document.getElementById('tdHoraSistema').innerHTML = horaImprimible

    setTimeout("mueveReloj()",1000)
}
function selectedOption(idLst, value) {
	var lista = document.getElementById(idLst);
	for(i=0; i <= lista.options.length; i++){
		if (lista.options[i] != null) {
			if(lista.options[i].value == value || lista.options[i].text == value){
				lista.options[i].selected = true;
				break;
			}
		}
	}
}

function selecAllChecks(chkVal, idVal, form) {
	var frm = document.forms[form];
	for (i = 0; i < frm.length; i++){
		if (frm.elements[i].id == idVal){
			if(chkVal == true && frm.elements[i].disabled == false){
				frm.elements[i].checked = true;
			} else {
				frm.elements[i].checked = false;
			}
		}
	}
}

/********** FUNCIONES PARA LOS POPUPS **********/
function centraPopUp(w,h) {
	var w = w + 10;
	var h = h + 29;
	var ns4 = (document.layers) ? true : false;
	var ie4 = (document.all) ? true : false;

	if(ns4) { // Noteskapes
		window.outerWidth  = w;
		window.outerHeight = h;
		var Xcor = (screen.width - window.outerWidth) / 2 - 5;
		var Ycor = (screen.height - window.outerHeight) / 2 - 14;
	} else	{ //else if(ie4) // Explorando
		var Ycor = (screen.height - h) / 2 - 14;
		var Xcor = (screen.width - w) / 2 - 5;
	}
	
	return 'top='+Ycor+', left='+Xcor;
}

function verVentana(pagina, width, height) {
	posicion = ', '+centraPopUp(width,height);
	var opciones="toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width="+width+", height="+height+posicion;
	window.open(pagina,"",opciones);
}



function findAlto(obj) {
	var curheight = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curheight += obj.offsetHeight
			obj = obj.offsetParent;
		}
	} else if (obj.h)
		curheight += obj.h;
	
	return curheight;
}
function findAncho(obj) {
	var curwidth = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curwidth += obj.offsetWidth
			obj = obj.offsetParent;
		}
	} else if (obj.w)
		curwidth += obj.w;
	
	return curwidth;
}
function findScreenAlto() {
	myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myHeight = window.innerHeight;
	} else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myHeight = document.documentElement.clientHeight;
	} else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myHeight = document.body.clientHeight;
	}
	
	return myHeight;
}
function findScreenAncho() {
	var myWidth = 0;
	if ( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
	} else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
	} else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
	}
	return myWidth;
}
function findScrollY() {
	var scrOfY = 0;
	if ( typeof(window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
	} else if ( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
	} else if ( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
	}
	return scrOfY;
}
// -----------------------------------------------------------------------
// PARA CENTRAR UN DIV
// -----------------------------------------------------------------------
function centrarDiv(div) {
	var h  = findAlto(div);
	var w  = findAncho(div);
	var sh = findScreenAlto();
	var sw = findScreenAncho();
	var scy = findScrollY();
	var top = (sh - h) /2;
	var left = (sw - w) /2;
	//alert("h="+h+", sh="+sh+", scy="+scy+", +"+(parseInt(top)+scy));
	if ( document.getElementById && !window.getComputedStyle ){// DOM but not Mozilla
		div.style.top= (parseInt(top)+scy)+ "px";
	} else {
		div.style.top= parseInt(top)+ "px";
	}
	div.style.left= parseInt(left)+ "px";
}